package behavioral.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 微信群
 * @Author: lxt
 * @CreateDate: 2019/11/1
 **/
public class Subject {
    private List<Observer> observers = new ArrayList<Observer>();

    public void addObserver(Observer observer) {
        this.observers.add(observer);
    }

    public void sendMessage(Observer observer, String message) {
        for (Observer obs : observers) {
            if(obs != observer){
                obs.receive(observer.getName(), message);
            }
        }
    }
}
